/*	COMP 6761 Assignment 1 Framework
	Created by Kaustubha Mendhurwar on 09/09/14.
	Copyright (c) 2014 Concordia University. All rights reserved.
*/

#pragma once
#include <stdio.h>
#include <string>
#include <iostream>
#include <fstream>
#include <algorithm>

#include "Renderer.h"
#include "EventManager.h"

#include <GLFW/glfw3.h>
using namespace std;


GLFWwindow* Renderer::spWindow = NULL;

void Renderer::Initialize()
{
	spWindow = EventManager::GetWindow();
	glfwMakeContextCurrent(spWindow);

	// Initialize GLEW
	glewExperimental = true; // Needed for core profile
	if (glewInit() != GLEW_OK) {
		fprintf(stderr, "Failed to initialize GLEW\n");
		
		getchar();
		exit(-1);
	}

	// Black background
	glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
	
	// Enable depth test
    glEnable(GL_DEPTH_TEST);
    
	// Accept fragment if it closer to the camera than the former one
    glDepthFunc(GL_LESS); 

}

void Renderer::Shutdown()
{
	// Managed by EventManager
	spWindow = NULL;
}

void Renderer::BeginFrame()
{
	// Clear the screen
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

}

void Renderer::EndFrame()
{
	// Swap buffers
	glfwSwapBuffers(spWindow);
}
